<?php
/**
 * 提现记录显示模块
 * UserModel:LLW
 * Date:2020-03-04
 */

namespace app\caidongweb\model;

class CashModel extends BaseModel
{
    protected $table = 'cd_cash';

    /**
     * 提现记录首页
     * @return \think\Paginator
     */
    public function getList($state = 0)
    {
        $where = [];
        $sta = strtotime(input('start'));
        $end = strtotime(input('end'));
        if($sta && $end){
            $where['ca_atime'] = array('between',"$sta,$end");
        }
        input('key') ? $where[input('city')] = input('key') : false;
        $where['ca_state'] = $state;
        $list = $this->alias('c')
            ->join('cd_user u','c.ca_uid=u.us_uid')
            ->where($where)->order('ca_atime desc')
            ->field('c.*,u.us_phone,u.us_closed_href,u.us_closed_code')
            ->paginate(20,false,['query'=>request()->param()]);
        return $list;
    }

    /**
     * 处理提现信息
     * @return array
     */
    public function getState()
    {
        //获取相关数据
        $data = input('post.');
        $find = $this->where('ca_id',$data['id'])->find();

        //信息验证
        if(empty($find)){
            return $this->returnData(-1,'提现信息未找到');
        }

        //提交数据
        $date['ca_state'] = 2;
        $date['ca_remark'] = $data['desc'];
        $res = $this->where('ca_id',$data['id'])->update($date);
        if($res){
            accountMoneyLog($find['ca_uid'],$find['ca_money'],'提现失败退回');
            return $this->returnData(1,'处理成功');
        }else{
            return $this->returnData(-1,'网络错误');
        }
    }
}